package com.momo.mal.util;

import net.momo.mal.R;
import com.momo.mal.anime.AnimeResult;
import com.momo.mal.manga.MangaResult;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.actionbarsherlock.app.SherlockDialogFragment;

public class DialogSearchMangaAnime extends SherlockDialogFragment {
	
	public DialogSearchMangaAnime newInstance() {
		DialogSearchMangaAnime dialog = new DialogSearchMangaAnime();
		
		return dialog;
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		LayoutInflater inflater = getActivity().getLayoutInflater();
		final View viewInflate = inflater.inflate(R.layout.dialog_search,
				null);
		final EditText editSearch = (EditText) viewInflate
				.findViewById(R.id.edit_search);

		builder.setTitle(getResources().getString(R.string.hint_anime_manga));
		builder.setView(viewInflate)
				.setPositiveButton(getResources().getString(R.string.hint_anime),
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int id) {
								Intent intent = new Intent(getActivity(),
										AnimeResult.class);

								String parse = editSearch.getText().toString()
										.replace(" ", "%20");
								intent.putExtra("query", parse + "");

								startActivity(intent);
							}
						})
				.setNegativeButton(getResources().getString(R.string.hint_manga),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								Intent intent = new Intent(getActivity(),
										MangaResult.class);
								String parse = editSearch.getText().toString()
										.replace(" ", "%20");
								intent.putExtra("query", parse + "");

								startActivity(intent);
							}
						});
		return builder.create();
	}
}
